from django.db import models
from django.conf import settings
from django.db.models import permalink
from django.core.files.storage import FileSystemStorage

import capabilities.models

fs = FileSystemStorage(location=settings.STATIC_ROOT, base_url=settings.STATIC_URL)

class Project(models.Model):
    """
    A project
    """
    author = capabilities.models.UserField()
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    url = models.URLField(blank=True, null=True)
    date = models.DateField(blank=True, null=True)
    summary = models.TextField()
    published = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    order = capabilities.models.OrderField()
    
    class Meta:
        ordering = ['order']
        
    @permalink
    def get_absolute_url(self):
        return ('arrt_project', [str(self.slug)])

    def __unicode__(self):
        return self.title
    
class Image(models.Model):
    """
    An image for a project
    """
    project = models.ForeignKey(Project)
    full_image = models.ImageField(storage=fs, upload_to='uploads/arrt/project/full_image', blank=True, null=True)
    image = models.ImageField(storage=fs, upload_to='uploads/arrt/project/image', blank=True, null=True)
    thumbnail = models.ImageField(storage=fs, upload_to='uploads/arrt/project/thumbnail', blank=True, null=True)
    order = capabilities.models.OrderField()
    
    class Meta:
        ordering = ['order']
        
    def __unicode__(self):
        return self.screenshot